package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	optimalDivision([]int{2, 3, 4})
}

func optimalDivision(nums []int) string {
	maxVal, minVal, maxStr, minStr := optimalDivisionHelper(nums)
	fmt.Println(maxVal, minVal, maxStr, minStr)
	return maxStr
}

func optimalDivisionHelper(nums []int) (maxVal, minVal float64, maxStr, minStr string) {
	if len(nums) == 1 {
		//	fmt.Println(nums[0], nums[0], strconv.Itoa(nums[0]), strconv.Itoa(nums[0]))
		return float64(nums[0]), float64(nums[0]), strconv.Itoa(nums[0]), strconv.Itoa(nums[0])
	}
	maxVal = 0
	minVal = math.MaxInt
	for i := 1; i < len(nums); i++ {
		maxLeft, minLeft, maxStrLeft, minStrLeft := optimalDivisionHelper(nums[:i])
		maxRight, minRight, maxStrRight, minStrRight := optimalDivisionHelper(nums[i:])
		if tmpMax := maxLeft / minRight; maxVal < tmpMax {
			maxVal = tmpMax
			if len(nums)-i > 1 {
				maxStr = maxStrLeft + "/(" + minStrRight + ")"
			} else {
				maxStr = maxStrLeft + "/" + minStrRight
			}
		}
		if tmpMin := minLeft / maxRight; minVal > tmpMin {
			minVal = tmpMin
			if len(nums)-i > 1 {
				minStr = minStrLeft + "/(" + maxStrRight + ")"
			} else {
				minStr = minStrLeft + "/" + maxStrRight
			}
		}
	}
	return
}
